package com.zjs.mq.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description Kafka消息生产者
 * @Author zhu_jinsheng[zhu_js@suixingpay.com]
 * @Date 2020/2/25 14:48
 * @Version 1.0
 */

@Slf4j
@Component
public class KafkaProducer {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    /**
     * 发送消息方法
     */
    public void send() {
        for (int i = 1; i <= 5; i++) {
            String message = "消息" + i;
            kafkaTemplate.send("hello", message);
            log.info("发送" + message);
        }
    }
}
